<template>
  <div class="login-container">
    <div class="login-box">
      <div class="login-left">
        <div class="title">高效记录生活</div>
        <div class="sub">轻松收集，有效整理</div>
        <img src="../assets/login.png" alt="" />
      </div>

      <div class="login-form">
        <div class="login-logo">
          <img class="login-icon" src="../assets/logo.png" alt="" />
          <p class="logo-text">欢迎登录</p>
        </div>
        <el-form
          ref="loginFormRef"
          :model="loginForm"
          :rules="loginRules"
          size="large"
        >
          <el-form-item prop="username">
            <el-input
              style="margin-top: 10%"
              :prefix-icon="User"
              v-model="loginForm.username"
              placeholder="用户名"
            >
            </el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              :prefix-icon="Lock"
              type="password"
              show-password
              v-model="loginForm.password"
              placeholder="密码"
            >
            </el-input>
          </el-form-item>
          <div class="flx-row">
            <el-checkbox
              style="flex: 1"
              v-model="loginForm.checked"
              label="记住密码"
              size="large"
            />
            <span>忘记密码？</span>
          </div>
        </el-form>

        <div class="login-btn">
          <el-button
            :icon="CircleClose"
            round
            @click="resetForm(loginFormRef)"
            size="large"
            >重置</el-button
          >
          <el-button
            :icon="UserFilled"
            round
            @click="login()"
            size="large"
            type="primary"
            :loading="loading"
          >
            登录
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import {
  CircleClose,
  UserFilled,
  Lock,
  User,
  Iphone,
} from "@element-plus/icons-vue";
import { onMounted, reactive, ref } from "vue";
import { ElMessage } from "element-plus";
import { Apilogin } from "../api/server";
import router from "@/router";
import { useStore} from '@/stores/counter'
const stores = useStore();
console.log(stores,'=====stores');

const loading = ref(false);
const loginFormRef = ref(false);
const loginForm = reactive({
  username: "",
  password: "",
  checked: true,
});

const loginRules = reactive({
  username: [{ required: true, message: "请输入用户名", trigger: "blur" }],
  password: [{ required: true, message: "请输入密码", trigger: "blur" }],
});
const login = async () => {
  // const res = await Apilogin(loginForm);
  // if (res.data.code === 200) {
  //   localStorage.setItem("token", res.data.token);
  //   ElMessage({
  //     message: "登录成功",
  //     type: "success",
  //   });
  //   router.push('/home/index')
  // }else{
  //    ElMessage('登录失败')
  // }
  // console.log(res, "login");
  stores.apigetlogin(loginForm)
};

const resetForm = () => {};
</script>

<style scoped lang="scss">
* {
  margin: 0;
  padding: 0;
}

.login-container {
  width: 100vw;
  height: 100vh;
  // background-color: #6c88d5;
  background: url("../assets/bg.png") no-repeat;
  background-size: 100% 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  // background: red;

  .login-box {
    width: 96%;
    height: 94%;
    background-color: hsla(0, 0%, 100%, 0.85);
    border-radius: 10px;
    padding: 0 8% 0 50px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-around;

    .login-left {
      width: 80%;

      color: #6e736fff;
      // background: red;

      .title {
        font-size: 32px;
        font-weight: 400;
        letter-spacing: 0px;
        color: rgba(47, 57, 78, 1);
        text-align: left;
      }

      img {
        width: 70%;
        height: 80%;
      }
    }

    .login-form {
      width: 35%;
      height: 62%;
      padding: 10px 40px 35px 40px;
      border-radius: 10px;
      -webkit-box-shadow: 2px 3px 7px rgb(0 0 0 / 20%);
      box-shadow: 2px 3px 7px rgb(0 0 0 / 20%);
      // background: pink;

      .login-logo {
        display: flex;
        align-items: center;
        justify-content: center;
        // background: red;
        margin-top: 7%;

        // margin-bottom: 45px;

        .login-icon {
          width: 60px;
          // height: 52px;
        }

        .logo-text {
          font-weight: bold;
          font-size: 32px;
          padding-left: 25px;
          white-space: nowrap;
          color: #2d51e6;
        }
      }

      .el-form-item {
        margin-bottom: 20px;
      }

      .flx-row {
        span {
          font-size: 14px;
          color: #2d51e6;
        }

        .img {
          flex: 1;
          text-align: center;
        }
      }

      .login-btn {
        margin-top: 20px;
        padding-bottom: 20px;
        display: flex;
        justify-content: space-between;
        width: 100%;
        white-space: nowrap;

        .el-button {
          width: 185px;
        }
      }
    }
  }
}
</style>